package com.ms.game.slot.base.table;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map.Entry;

import com.ms.service.error.ErrorCode;



/**
 * T = 個人資訊  ,  設定繼承DMBasicTableUser
 * T2 = 館別設定
 * @author TW15012
 * @param <T>
 * @param <T2>
 */
public class DMBasicTableUserManager <T , T2> 
{
	private HashMap<String,DMBasicTableUserInfo<T, T2>> table = new HashMap<String,DMBasicTableUserInfo<T, T2>>();

	public HashMap<String, DMBasicTableUserInfo<T, T2>> getTable() {
		return table;
	}

	public void setTable(HashMap<String, DMBasicTableUserInfo<T, T2>> table) {
		this.table = table;
	}
	
	public ArrayList<T> getAllUserInfo(String guid)
	{
		ArrayList<T> list = new ArrayList<T>();
		for(Entry<String,DMBasicTableUserInfo<T, T2>> entry:table.entrySet())
		{
			DMBasicTableUserInfo<T, T2> halldata = entry.getValue();
			list.add(halldata.getUser(guid));
		}
		
		return list;
	}
	
	
	public int putUser(String halltype , T user)
	{
		if(!table.containsKey(halltype))
		{
			return ErrorCode.INVALID_HALL_TYPE;
		}
		DMBasicTableUserInfo<T, T2> halldata = table.get(halltype);
		return halldata.putUser(user);
	}
	
	public int removeUser(String halltype , String guid)
	{
		if(!table.containsKey(halltype))
		{
			return ErrorCode.INVALID_HALL_TYPE;
		}
		
		DMBasicTableUserInfo<T, T2> halldata = table.get(halltype);
		halldata.removeUser(guid);
		return ErrorCode.SUCCESS;
	}
	
	
	public T getUser(String halltype,String guid)
	{
		if(!table.containsKey(halltype))
		{
			return null;
		}
		
		DMBasicTableUserInfo<T, T2> halldata = table.get(halltype);
		return halldata.getUser(guid);
	}
	
	/**
	 * 玩家是否在驗證中
	 * @param halltype
	 * @param guid
	 * @return
	 */
	public boolean isVerify(String halltype,String guid)
	{
		if(!table.containsKey(halltype))
		{
			return true;
		}
		
		DMBasicTableUserInfo<T, T2> halldata = table.get(halltype);
		DMBasicTableUser user= (DMBasicTableUser)halldata.getUser(guid);
		return user.isVerify();
	}
	
	/**
	 * 讀取館玩家列表
	 * @param halltype
	 * @return
	 */
	public ArrayList<T> getUserList(String halltype)
	{
		if(!table.containsKey(halltype))
		{
			return null;
		}
		
		return  table.get(halltype).getUserList();
	}
	
	/**
	 * 讀取館玩家個數
	 * @param halltype
	 * @return
	 */
	public int getUserCount(String halltype)
	{
		if(!table.containsKey(halltype))
		{
			return 0;
		}
		
		return  table.get(halltype).getSize();
	}
	
	/**
	 * 設定user 驗證狀態
	 * @param guid
	 * @param isverify
	 */
	public void setUserVerify(String halltype , String guid , boolean isverify)
	{
		if(!table.containsKey(halltype))
		{
			return;
		}
		
		DMBasicTableUserInfo<T, T2> halldata = table.get(halltype);
		halldata.setUserVerify(guid, isverify);
	}
	
	public T2 getOption(String halltype)
	{
		if(!table.containsKey(halltype))
		{
			return null;
		}
		
		return table.get(halltype).getOption();
	}
	
	public DMBasicTableUserInfo<T, T2> getTable(String halltype)
	{
		if(!table.containsKey(halltype))
		{
			return null;
		}
		
		return table.get(halltype);
	}
}
